import { PrismaClient } from '@prisma/client'
import { Random } from 'mockjs'
import { hash } from 'argon2'

const prisma = new PrismaClient()
const run = async () => {
  // 新建用户
  for (let index = 0; index < 10; index++) {
    await prisma.user.create({
      data: {
        name: Random.cword(2, 4),
        email: Random.email(),
        password: await hash('abc'),
      },
    })
  }

  await prisma.user.update({
    where: { id: 1 },
    data: {
      name: '刘晶',
      email: '275059231@qq.com',
      password: await hash('123'),
    },
  })

  await prisma.user.update({
    where: { id: 2 },
    data: {
      name: '范辉',
      email: '275059231@qq.com',
      password: await hash('123'),
    },
  })

  // 新建工程
  for (let index = 0; index < 10; index++) {
    for (let i = 0; i < 4; i++) {
      await prisma.proj.create({
        data: {
          name: Random.cword(5, 10),
          shortName: Random.cword(3, 5),
          userId: index + 1,
        },
      })
    }
  }

  // 新建放线区段
  for (let index = 0; index < 40; index++) {
    for (let x = 0; x < 5; x++) {
      await prisma.section.create({
        data: {
          name: Random.cword(4, 8),
          projId: index + 1,
        },
      })
    }
  }
}

run()
